using Assets.Scripts.GDK;
using System;
using UnityEngine;
using UnityEngine.UI;

namespace Brick
{
	[RequireComponent(typeof(Image))]
	[RequireComponent(typeof(RectTransform))]
	[RequireComponent(typeof(Toggle))]
	public class gdk_toggle : gdk_v_component
	{
		public Action<bool> OnToggleChanged;

		public override void OnLoad()
		{
			init();
		}

		private void init()
		{
			Toggle component = base.gameObject.GetComponent<Toggle>();
			component.transition = Selectable.Transition.None;
			component.onValueChanged.AddListener(delegate (bool isOn)
			{
				OnToggleValueChanged(isOn);
			});
		}

		private void OnToggleValueChanged(bool isOn)
		{
			if (OnToggleChanged != null)
			{
				OnToggleChanged(isOn);
			}
			gdk_utils.FindChild(base.gameObject.transform, "on").gameObject.SetActive(!isOn);
			gdk_utils.FindChild(base.gameObject.transform, "off").gameObject.SetActive(isOn);
		}

		public void onData(bool isOn)
		{
			OnToggleValueChanged(isOn);
		}
	}
}

